package stu.day19_day24.day19;

import java.util.HashMap;

public class LeetCode974 {
    public int subarraysDivByK(int[] nums, int k) {

        HashMap<Integer, Integer> map = new HashMap<>();

        map.put(0, 1);

        int sum = 0;
        int num = 0;
        for (int j : nums) {
            sum += j;
            int yu = sum%k;
            int fu = yu >0?-(k- yu):k+ yu;
            if (map.containsKey(yu)) {
                num += map.get(yu);
            }
            if (map.containsKey(fu)&& yu !=0) {
                num += map.get(fu);
            }

           map.put(yu,map.getOrDefault(yu,0)+1);
        }

        return num;

    }

    public static void main(String[] args) {
        System.out.println(-7%4);
        System.out.println(3%5);
        System.out.println((-2-3)%5);
    }
}
